package com.swak.generate.codegen;

import java.util.List;

/**
 * 表
 * 
 * @author lifeng
 */
public class Table {

	private String name;
	private List<TableColumn> columns;

	public List<TableColumn> getColumns() {
		return columns;
	}

	public void setColumns(List<TableColumn> columns) {
		this.columns = columns;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPkJavaType() {
		if (this.columns != null && this.columns.size() != 0) {
			for (TableColumn column : columns) {
				if (1 == column.getIsPk()) {
					return column.getJavaType();
				}
			}
		}
		return "String";// 默认string
	}

	/**
	 * 是否是Long 的主键
	 * 
	 * @return
	 */
	public Boolean getIsLongPk() {
		if (this.columns != null && this.columns.size() != 0) {
			for (TableColumn column : columns) {
				if (column.getIsPk() == 1 && column.getJavaType().equals("Long")) {
					return Boolean.TRUE;
				}
			}
		}
		return Boolean.FALSE;
	}

	/**
	 * 父类是否是 有日期字段
	 * 
	 * @return
	 */
	public Boolean getIsHasDate() {
		if (this.columns != null && this.columns.size() != 0) {
			for (TableColumn column : columns) {
				if (column.getIsDateColumn()) {
					return Boolean.TRUE;
				}
			}
		}
		return Boolean.FALSE;
	}

	/**
	 * 父类是否是
	 * 
	 * @return
	 */
	public Boolean getIsBaseEntity() {
		if (this.columns != null && this.columns.size() != 0) {
			for (TableColumn column : columns) {
				if (column.getIsBaseEntity()) {
					return Boolean.TRUE;
				}
			}
		}
		return Boolean.FALSE;
	}
	
	/**
	 * 是否是租户
	 * 
	 * @return
	 */
	public Boolean getIsTenant() {
		if (this.columns != null && this.columns.size() != 0) {
			for (TableColumn column : columns) {
				if (column.getIsTennatColumn()) {
					return Boolean.TRUE;
				}
			}
		}
		return Boolean.FALSE;
	}
}